-------------------------------------------------------------
package.cpath = '../../../luaclib/?.so;' .. package.cpath
package.path = '/data/color-server/frame/tablesvr/games/?.lua;../../../common/?.lua;' .. '../../../lualib/?.lua;' .. '/data/configs/?.lua;' .. package.path

local brnn     = require "brnn"
local roomdata = require "roomdata"
local brnn_banker = require "brnn_banker"
local table_insert = table.insert
local table_remove = table.remove

local print = print

require "preload"

_ENV.print = print
_ENV.tostring_r = tostring_r

-- while true do 
--     local curr_banker_uid = 88888
--     local self_table_type = 200004
--     local card_type_times_map = {
--         [1] = 1,
--         [2] = 1,
--         [3] = 1,
--         [4] = 1,
--         [5] = 1,
--         [6] = 1,
--         [7] = 2,
--         [8] = 2,
--         [9] = 2,
--         [10] = 3,
--         [14] = 3,
--         [15] = 3,
--         [16] = 3,
--         [0] = 1,
--     }
--     local sorted_special_card_type = {
--         [1] = 14,
--         [2] = 15,
--         [3] = 16,
--     }

--     local instance = brnn:new()
--     instance:init(card_type_times_map,sorted_special_card_type,self_table_type)
--     instance:set_banker(curr_banker_uid)
--     instance:init_player_coins(curr_banker_uid,-1)

--     local robot_get_best_cards = nil
--     print("brnn_banker============",brnn_banker)
--     instance:deal(robot_get_best_cards,self_table_type,roomdata,brnn_banker)
-- end

local function copy_table(t)
    local new_t = {}
    for k,v in pairs(t) do
        new_t[k] = v
    end
    return new_t
end

local function make_card_id(sign, number)
    return sign * 100 + number
end

local all_cards = {}
for i = 1, 13 do
    for j = 1, 4 do
        table_insert(all_cards,make_card_id(j, i))
    end
end

for k,v in pairs(all_cards) do
    print(k,v)
end

local side_cards_map = {
    [1] = {101,201,301,401,102},
    [2] = {202,302,402,103,203},
    [3] = {303,404,104,204,304},
    [4] = {404,105,205,305,405},
    [5] = {106,206,306,406,107},
}

local function have_used_card(deal_card)
    for side,side_cards in pairs(side_cards_map) do
        for k, card in pairs(side_cards) do
            if deal_card == card then
                return true
            end
        end
    end
    return false
end

local function update_rest_cards()
    local rest_cards = copy_table(all_cards)
    for i=#rest_cards,1,-1 do
        local is_have = have_used_card(rest_cards[i])
        print("update_rest_cards========",i,rest_cards[i],is_have)
        if have_used_card(rest_cards[i]) then
            table_remove(rest_cards,i)
        end
    end

    return rest_cards
end

local rest_cards = update_rest_cards()
for k,v in pairs(rest_cards) do
    if have_used_card(v) then
        print("=====================",v)
    end
end

-- local side_cards_map = {
--     [1] = {406,311,205,313,209},
--     [2] = {310,304,202,311,104},
--     [3] = {},
--     [4] = {},
--     [5] = {201,413,307,312,402},
-- }
